import Vue from 'vue';
import Router from 'vue-router';

Vue.use(Router);

/**
 * Note: 路由配置项
 *
 * hidden: true                     // 当设置 true 的时候该路由不会再侧边栏出现 如401，login等页面，或者如一些编辑页面/edit/1
 * alwaysShow: true                 // 当你一个路由下面的 children 声明的路由大于1个时，自动会变成嵌套的模式--如组件页面
 *                                  // 只有一个时，会将那个子路由当做根路由显示在侧边栏--如引导页面
 *                                  // 若你想不管路由下面的 children 声明的个数都显示你的根路由
 *                                  // 你可以设置 alwaysShow: true，这样它就会忽略之前定义的规则，一直显示根路由
 * redirect: noRedirect             // 当设置 noRedirect 的时候该路由在面包屑导航中不可被点击
 * name:'router-name'               // 设定路由的名字，一定要填写不然使用<keep-alive>时会出现各种问题
 * query: '{"id": 1, "name": "ry"}' // 访问路由的默认传递参数
 * roles: ['admin', 'common']       // 访问路由的角色权限
 * permissions: ['a:a:a', 'b:b:b']  // 访问路由的菜单权限
 * meta : {
    noCache: true                   // 如果设置为true，则不会被 <keep-alive> 缓存(默认 false)
    title: 'title'                  // 设置该路由在侧边栏和面包屑中展示的名字
    icon: 'svg-name'                // 设置该路由的图标，对应路径src/assets/icons/svg
    breadcrumb: false               // 如果设置为false，则不会在breadcrumb面包屑中显示
    activeMenu: '/system/user'      // 当路由设置了该属性，则会高亮相对应的侧边栏。
  }
 */

// 公共路由
export const constantRoutes = [
  // {
  //   path: '/redirect',
  //   component: Layout,
  //   hidden: true,
  //   children: [
  //     {
  //       path: '/redirect/:path(.*)',
  //       component: () => import('@/views/redirect')
  //     }
  //   ]
  // },
  {
    path: '/login',
    component: () => import('@/views/login/index.vue'),
    hidden: true,
  },
  // {
  //   path: '/register',
  //   component: () => import('@/views/register'),
  //   hidden: true
  // },
  // {
  //   path: '/404',
  //   component: () => import('@/views/error/404'),
  //   hidden: true
  // },
  // {
  //   path: '/401',
  //   component: () => import('@/views/error/401'),
  //   hidden: true
  // },
  {
    path: '',
    redirect: '/home',
  },
  {
    path: '/home',
    component: () => import('@/views/home/index'),
    name: 'Index',
    meta: { title: '首页' },
  },
  {
    path: '/user',
    component: () => import('@/views/user/index'),
    name: 'User',
    meta: { title: '我的' },
  },
  {
    path: '/user/examTestRecord',
    component: () => import('@/views/user/page/examTestRecord'),
    name: 'UserExamTestRecord',
    meta: { title: '测评记录' },
  },
  {
    path: '/user/activity',
    component: () => import('@/views/user/page/activity'),
    name: 'UserActivity',
    meta: { title: '我的活动' },
  },
  // 工会新闻
  {
    path: '/groupInfo',
    component: () => import('@/views/laborNews/groupInfo.vue'),
    name: 'GroupInfo',
    meta: { title: '集团信息' },
  },
  {
    path: '/companyNews',
    component: () => import('@/views/laborNews/companyNews.vue'),
    name: 'CompanyNews',
    meta: { title: '省公司动态' },
  },
  // {
  //   path: '/grassrootsNews',
  //   component: () => import('@/views/laborNews/grassrootsNews.vue'),
  //   name: 'GrassrootsNews',
  //   meta: { title: '基层动态' },
  // },
  // 活动
  {
    path: '/condolenceDistribution/index',
    component: () => import('@/views/condolenceDistribution/index'),
    name: 'CondolenceDistributionIndex',
    meta: { title: '慰问品发放首页' },
  },
  {
    path: '/condolenceDistribution/detail',
    component: () => import('@/views/condolenceDistribution/page/detail.vue'),
    name: 'CondolenceDistributionDetail',
    meta: { title: '慰问品发放详情' },
  },
  {
    path: '/activityRegister/index',
    component: () => import('@/views/activityRegister/index'),
    name: 'ActivityRegisterIndex',
    meta: { title: '活动报名首页' },
  },
  {
    path: '/activityRegister/detail',
    component: () => import('@/views/activityRegister/page/detail.vue'),
    name: 'ActivityRegisterDetail',
    meta: { title: '活动报名详情' },
  },
  {
    path: '/activityRegister/register',
    component: () => import('@/views/activityRegister/page/register.vue'),
    name: 'ActivityRegisterRegister',
    meta: { title: '活动报名操作' },
  },
  {
    path: '/vote/index',
    component: () => import('@/views/vote/index'),
    name: 'VoteIndex',
    meta: { title: '投票首页' },
  },
  {
    path: '/vote/detail1',
    component: () => import('@/views/vote/page/detail1.vue'),
    name: 'VoteDetail1',
    meta: { title: '投票详情' },
  },
  {
    path: '/vote/detail2',
    component: () => import('@/views/vote/page/detail2.vue'),
    name: 'VoteDetail2',
    meta: { title: '投票详情' },
  },
  {
    path: '/vote/optionDetail',
    component: () => import('@/views/vote/page/optionDetail.vue'),
    name: 'VoteOptionDetail',
    meta: { title: '投票选项详情' },
  },
  {
    path: '/booking/index',
    component: () => import('@/views/booking/index'),
    name: 'BookingIndex',
    meta: { title: '订场首页' },
  },
  {
    path: '/booking/detail',
    component: () => import('@/views/booking/page/detail.vue'),
    name: 'BookingDetail',
    meta: { title: '订场详情' },
  },
  // 心灵驿站
  {
    path: '/mindStation/index',
    component: () => import('@/views/mindStation/index'),
    name: 'MindStationIndex',
    meta: { title: '心灵驿站首页' },
  },
  {
    path: '/mindStation/user',
    component: () => import('@/views/mindStation/user'),
    name: 'MindStationUser',
    meta: { title: '心灵驿站我的' },
  },
  {
    path: '/mindStation/mindProbes',
    component: () => import('@/views/mindStation/page/mindProbes.vue'),
    name: 'MindProbes',
    meta: { title: '心理探针' },
  },
  {
    path: '/mindStation/examTest',
    component: () => import('@/views/mindStation/page/examTest.vue'),
    name: 'ExamTest',
    meta: { title: '题目测评' },
  },
  {
    path: '/mindStation/mindCare',
    component: () => import('@/views/mindStation/page/mindCare.vue'),
    name: 'MindCare',
    meta: { title: '心理辅导' },
  },
  {
    path: '/mindStation/mindClasses',
    component: () => import('@/views/mindStation/page/mindClasses.vue'),
    name: 'MindClasses',
    meta: { title: '心理科普' },
  },
  {
    path: '/mindStation/aiCustomerService',
    component: () => import('@/views/mindStation/page/aiCustomerService.vue'),
    name: 'AiCustomerService',
    meta: { title: 'Ai客服' },
  },
  // 保险经纪人
  {
    path: '/insuranceRecommend',
    component: () => import('@/views/InsuranceRecommend/index.vue'),
    name: 'InsuranceRecommend',
    meta: { title: '保险经纪人' },
  },
];

// 动态路由，基于用户权限动态去加载
export const dynamicRoutes = [];

// 防止连续点击多次路由报错
let routerPush = Router.prototype.push;
let routerReplace = Router.prototype.replace;
// push
Router.prototype.push = function push(location) {
  return routerPush.call(this, location).catch((err) => err);
};
// replace
Router.prototype.replace = function push(location) {
  return routerReplace.call(this, location).catch((err) => err);
};

export default new Router({
  mode: 'history', // 去掉url中的#
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes,
});
